<?php

namespace app\admin\model\yunfood;

use addons\yunfood\library\Logic;

/**
 * 门店
 */
class Shop extends \addons\yunfood\model\Shop
{
    // 自定义初始化
    protected static function init()
    {
        self::beforeWrite(function ($record) {
            $scenario = $record->data['scenario'] ?? null;
            if ($scenario) {
                $adminIds = $record->data['admin_ids'];
                $record->admin_ids = implode(',', $adminIds);
            }
        });
    }

    // 封面图 - 覆盖父类
    public function getCoverUrlAttr($value, $data)
    {
        return $value;
    }

    protected function setStartTimeAttr($value)
    {
        return $value && ! is_numeric($value) ? Logic::hourTimeToInt($value) : $value;
    }

    protected function getStartTimeAttr($value)
    {
        return Logic::intToHourTime($value);
    }

    protected function setEndTimeAttr($value)
    {
        return $this->setStartTimeAttr($value);
    }

    protected function getEndTimeAttr($value)
    {
        return $this->getStartTimeAttr($value);
    }
}
